﻿#include "getTempThread.h"
#include <QDebug>
#include <mainwindow.h>

using namespace std;
GetTempThread::GetTempThread(QObject *parent): QObject{parent}
{
    this->moveToThread(&thread);
    thread.start();
}

void GetTempThread::run()
{
    if(MainWindow::connectType==0){
        tcpClient= TcpClient::getInstance();
    }
    else if(MainWindow::connectType==1){
        serialClient=SerialportThread::getInstance();
    }

    commonClient=CommonHelper::commonInstance();
    logClient=loghelper::getInstance();

    while (MainWindow::experimentStatus.get()==1) {
        if (MainWindow::tempOrder==6) {
            QString sendInfo="62 00 00 3A 00 08 00 00 00 01 00 06 E6 6F 55 AA";
            QByteArray finalInfo=commonClient->GetSendData(sendInfo);

            if(MainWindow::connectType==0){
                tcpClient->ClientSendingData(finalInfo);
            }
            else if(MainWindow::connectType==1){
                serialClient->serialPortSend(finalInfo);
            }

            logClient->WriteLog("CommLog","发送:\n"+sendInfo);\
            MainWindow::tempOrder=1;
        }
        else if(MainWindow::tempOrder==8){
            MainWindow::experimentStatus.set(2);
        }
        else
        {
            QString sendInfo="62 00 00 3A 00 0A 00 00 00 01 00 05 E7 2F 55 AA";
            QByteArray finalInfo=commonClient->GetSendData(sendInfo);

            if(MainWindow::connectType==0){
                tcpClient->ClientSendingData(finalInfo);
            }
            else if(MainWindow::connectType==1){
                serialClient->serialPortSend(finalInfo);
            }

            logClient->WriteLog("CommLog","发送:\n"+sendInfo);
        }
        thread.sleep(2);
    }
    thread.quit();
}
